<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Validator;

class PolityChoiceWebRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    public function addCheck()
    {
        Validator::extend('is_equal', function ($attribute, $value, $parameters, $validator) {
            return count($value) == count(request('right'));
        });
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $this->addCheck();
        return [
            'answer' => 'required|is_equal'
        ];
    }

    public function messages()
    {
        return [
            'answer.required' => '不允许提交白卷！',
            'answer.is_equal' => '没有完成的考试！'
        ];
    }
}
